<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件化的基本使用</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
    <div id="app">
        <cpn1></cpn1>
        <cpn2></cpn2>
    </div>
    <!-- 1.组件分离写法，写到这里 通过script标签 -->
    <script type="text/x-template" id="cpn1">
        <div>
            <h2>{{title}}</h2>
            <p>我是内容1</p>
        </div>
    
    </script>

    <!-- 2.通过template标签 -->
    <template id="cpn2">
        <div>
            <h2>我是标题2</h2>
            <p>我是内容2</p>
        </div>
    </template>
    <script>
       
        Vue.component('cpn1', {
            template: "#cpn1",
            data(){//数据存放在这里，组件中data是函数，返回一个对象
                return{
                    title:'我是标题1'
                }
            }
               
        })

        const app = new Vue({
            el: "#app",
            data: {
                
            },
            components:{//局部组件注册语法糖
                cpn2:{
                    template: "#cpn2"
                }
            }
        })
    </script>
</body>
</html>